package com.aiit.service.impl;

import com.aiit.dao.TaskManageDao;
import com.aiit.pojo.bo.Task;
import com.aiit.pojo.bo.User;
import com.aiit.pojo.vo.UserStatus;
import com.aiit.service.TaskManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskManageServiceImpl implements TaskManageService {
    @Autowired
    private TaskManageDao taskManageDao;

    @Override
    public List<User> selectAllName() {
        return taskManageDao.selectAllName();
    }

    @Override
    public int addTask(Task task) {
        return taskManageDao.addTask(task);
    }

    @Override
    public int addIds(String createTime, int userid, String status) {
        return taskManageDao.addIds(createTime,userid,status);
    }

    @Override
    public int add(Task task, String time, String[] peopleIds) {
        int a=addTask(task);
        int b=0;
        for (String string : peopleIds) {
            int userid=Integer.parseInt(string);
            b=addIds(time,userid,"待办");
        }
        if(a==1&&b==1){
            return 0;
        }
        return -1;
    }

    @Override
    public List<Task> selectAll() {
        return taskManageDao.selectAll();
    }

    @Override
    public List<Task> searchTaskByParam(String title, String create_time, String finish_time) {
        return taskManageDao.searchTaskByParam(title, create_time, finish_time);
    }

    @Override
    public List<UserStatus> selectUsersByID(int id) {
        return taskManageDao.selectUsersByID(id);
    }
}
